package com.cloud.train.member.controller;

import com.cloud.train.common.resp.CommonResp;
import com.cloud.train.member.req.MemberLoginReq;
import com.cloud.train.member.req.MemberRegisterReq;
import com.cloud.train.member.req.MemberSetCode;
import com.cloud.train.member.resp.MemberLoginResp;
import com.cloud.train.member.service.MemberService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/member")
public class MemberController {
    @Resource
    private MemberService memberService;
    @GetMapping("/count")
    public CommonResp<Integer> count(){
        int count = memberService.count();
        CommonResp<Integer> commonResp = new CommonResp<>();
        commonResp.setContent(count);
        return commonResp;
    }
    @PostMapping("/register")
    public CommonResp<Long> register(@Valid MemberRegisterReq req){
        long register = memberService.register(req);
//        CommonResp<Long> longCommonResp = new CommonResp<>();
//        longCommonResp.setContent(register);
        return new CommonResp<>(register);
    }
    @PostMapping("/send_code")
    public CommonResp<Long> SendCode(@Valid @RequestBody MemberSetCode code){
        memberService.setCode(code);
        return new CommonResp<>();
    }

    @PostMapping("/login")
    public CommonResp<MemberLoginResp> Login(@Valid @RequestBody MemberLoginReq req){
        MemberLoginResp login = memberService.Login(req);
        return new CommonResp<>(login);
    }
    @GetMapping("/hello")
    public String hello(){
        return "hello,world";
    }
}
